﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace Web_HengliSeed.BLL
{
    public class CompanyInfo
    {
        /// <summary>
        /// 获取网站基本信息
        /// </summary>
        /// <param name="strType">字段类型</param>
        /// <returns></returns>
        public static OleDbDataReader GetWebBaseInfo(string strType)
        {
            try
            {
                string strSql = string.Empty;
                switch (strType)
                {
                    case "foot":
                        strSql = " SELECT T_CompanyName,T_CompanyTel,T_CompanyFax,T_CompanyMail,T_CompanyAdress,T_CompanyNo ";
                        break;
                    case "head":
                        strSql = " SELECT T_CompanyName,T_CompanyKey,T_CompanyDes ";
                        break;
                    case "about":
                        strSql = " SELECT T_CompanyAbout ";
                        break;
                    case "compay":
                        strSql = " SELECT T_CompanyTender ";
                        break;
                    case "link":
                        strSql = " SELECT T_CompanyLink ";
                        break;
                }
                strSql += " FROM T_CompanyInfo  ";
                return ClassFile.AccessHelper.ExecuteReader(ClassFile.AccessHelper.ConnectionString, strSql, null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 更新企业简介信息
        /// </summary>
        /// <param name="CompanyAbout"></param>
        /// <returns></returns>
        public static bool UpdateCompanyAbout(StringBuilder CompanyAbout)
        {
            OleDbParameter[] parm = { new OleDbParameter("@T_CompanyAbout", CompanyAbout.ToString()) };
            StringBuilder strSql = new StringBuilder();
            if (CheckCompanyMes())
            {
                strSql.Append(" INSERT INTO T_CompanyInfo(T_CompanyAbout) VALUES(@T_CompanyAbout) ");
            }
            else
            {
                strSql.Append("UPDATE T_CompanyInfo SET T_CompanyAbout=@T_CompanyAbout");
            }
            try
            {
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql.ToString(), parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 更新公司联系信息
        /// </summary>
        /// <param name="CompanyLink"></param>
        /// <returns></returns>
        public static bool UpdateCompanyLink(StringBuilder CompanyLink)
        {
            try
            {
                OleDbParameter[] parm = { new OleDbParameter("@T_CompanyLink", CompanyLink.ToString()) };
                StringBuilder strSql = new StringBuilder();
                if (CheckCompanyMes())
                {
                    strSql.Append(" INSERT INTO T_CompanyInfo(T_CompanyLink) VALUES(@T_CompanyLink) ");
                }
                else
                {
                    strSql.Append("UPDATE T_CompanyInfo SET T_CompanyLink=@T_CompanyLink");
                }
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql.ToString(), parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 更新公司招聘信息
        /// </summary>
        /// <param name="CompanyLink"></param>
        /// <returns></returns>
        public static bool UpdateCompanyJob(StringBuilder CompanyJob)
        {
            try
            {
                OleDbParameter[] parm = { new OleDbParameter("@T_CompanyLink", CompanyJob.ToString()) };
                StringBuilder strSql = new StringBuilder();
                if (CheckCompanyMes())
                {
                    strSql.Append(" INSERT INTO T_CompanyInfo(T_CompanyJob) VALUES(@T_CompanyJob) ");
                }
                else
                {
                    strSql.Append("UPDATE T_CompanyInfo SET T_CompanyJob=@T_CompanyJob");
                }
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql.ToString(), parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 更新公司招商信息
        /// </summary>
        /// <param name="CompanyLink"></param>
        /// <returns></returns>
        public static bool UpdateCompanyTender(StringBuilder CompanyTender)
        {
            try
            {
                OleDbParameter[] parm = { new OleDbParameter("@T_CompanyTender", CompanyTender.ToString()) };
                StringBuilder strSql = new StringBuilder();
                if (CheckCompanyMes())
                {
                    strSql.Append(" INSERT INTO T_CompanyInfo(T_CompanyJob) VALUES(@T_CompanyTender) ");
                }
                else
                {
                    strSql.Append("UPDATE T_CompanyInfo SET T_CompanyTender=@T_CompanyTender");
                }
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql.ToString(), parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 更新公司公告信息
        /// </summary>
        /// <param name="CompanyLink"></param>
        /// <returns></returns>
        public static bool UpdateCompanyNotice(StringBuilder CompanyNotice)
        {
            try
            {
                OleDbParameter[] parm = { new OleDbParameter("@T_CompanyNotice", CompanyNotice.ToString()) };
                StringBuilder strSql = new StringBuilder();
                if (CheckCompanyMes())
                {
                    strSql.Append(" INSERT INTO T_CompanyInfo(T_CompanyNotice) VALUES(@T_CompanyNotice) ");
                }
                else
                {
                    strSql.Append("UPDATE T_CompanyInfo SET T_CompanyNotice=@T_CompanyNotice");
                }
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql.ToString(), parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 更新公司其他信息
        /// </summary>
        /// <param name="T_CompanyName">公司名称</param>
        /// <param name="T_CompanyTel">公司电话</param>
        /// <param name="T_CompanyFax">传真</param>
        /// <param name="T_CompanyMail">E—Mail</param>
        /// <param name="T_CompanyAdress">联系地址</param>
        /// <param name="T_CompanyNo">网站备案号</param>
        /// <returns></returns>
        public static bool UpdateCompanyInfo(string T_CompanyName, string T_CompanyTel, string T_CompanyFax, string T_CompanyMail, string T_CompanyAdress, string T_CompanyNo)
        {
            try
            {
                OleDbParameter[] parm = { new OleDbParameter("@T_CompanyName", T_CompanyName),
                                      new OleDbParameter("@T_CompanyTel", T_CompanyTel),
                                      new OleDbParameter("@T_CompanyFax", T_CompanyFax),
                                      new OleDbParameter("@T_CompanyMail", T_CompanyMail),
                                      new OleDbParameter("@T_CompanyAdress", T_CompanyAdress),
                                      new OleDbParameter("@T_CompanyNo", T_CompanyNo)};
                StringBuilder strSql = new StringBuilder();
                if (CheckCompanyMes())
                {
                    strSql.Append(" INSERT INTO T_CompanyInfo(T_CompanyName,T_CompanyTel,T_CompanyFax,T_CompanyMail,T_CompanyAdress,T_CompanyNo) VALUES(@T_CompanyName,@T_CompanyTel,@T_CompanyFax,@T_CompanyMail,@T_CompanyAdress,@T_CompanyNo) ");
                }
                else
                {
                    strSql.Append("UPDATE T_CompanyInfo SET T_CompanyName=@T_CompanyName,T_CompanyTel=@T_CompanyTel,T_CompanyFax=@T_CompanyFax,T_CompanyMail=@T_CompanyMail,T_CompanyAdress=@T_CompanyAdress,T_CompanyNo=@T_CompanyNo");
                }
                return (ClassFile.AccessHelper.ExecuteNonQuery(ClassFile.AccessHelper.ConnectionString, strSql.ToString(), parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        /// <summary>
        /// 判断表里是否有数据
        /// </summary>
        /// <returns></returns>
        public static bool CheckCompanyMes()
        {
            try
            {
                return (ClassFile.AccessHelper.ExecuteScalar(ClassFile.AccessHelper.ConnectionString, " SELECT COUNT(*) FROM T_CompanyInfo ", null).ToString() == "0") ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取公司简介信息
        /// </summary>
        /// <param name="strClass"></param>
        /// <returns></returns>
        public static StringBuilder GetCompanyAbout()
        {
            try
            {
                StringBuilder CompanyMes = new StringBuilder();
                OleDbDataReader DataRead = ClassFile.AccessHelper.ExecuteReader(ClassFile.AccessHelper.ConnectionString, " SELECT T_CompanyAbout FROM T_CompanyInfo ", null);
                if (DataRead.HasRows)
                {
                    while (DataRead.Read())
                    {
                        CompanyMes.Append(DataRead["T_CompanyAbout"].ToString());
                    }
                }
                DataRead.Close();
                DataRead.Dispose();
                return CompanyMes;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取公司联系信息
        /// </summary>
        /// <param name="strClass"></param>
        /// <returns></returns>
        public static StringBuilder GetCompanyLink()
        {
            try
            {
                StringBuilder CompanyMes = new StringBuilder();
                OleDbDataReader DataRead = ClassFile.AccessHelper.ExecuteReader(ClassFile.AccessHelper.ConnectionString, " SELECT T_CompanyLink FROM T_CompanyInfo ", null);
                if (DataRead.HasRows)
                {
                    while (DataRead.Read())
                    {
                        CompanyMes.Append(DataRead["T_CompanyLink"].ToString());
                    }
                }
                DataRead.Close();
                DataRead.Dispose();
                return CompanyMes;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取公司招聘信息 
        /// </summary>
        /// <param name="strClass"></param>
        /// <returns></returns>
        public static StringBuilder GetCompanyJob()
        {
            try
            {
                StringBuilder CompanyMes = new StringBuilder();
                OleDbDataReader DataRead = ClassFile.AccessHelper.ExecuteReader(ClassFile.AccessHelper.ConnectionString, " SELECT T_CompanyJob FROM T_CompanyInfo ", null);
                if (DataRead.HasRows)
                {
                    while (DataRead.Read())
                    {
                        CompanyMes.Append(DataRead["T_CompanyJob"].ToString());
                    }
                }
                DataRead.Close();
                DataRead.Dispose();
                return CompanyMes;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 获取公司招商信息 
        /// </summary>
        /// <param name="strClass"></param>
        /// <returns></returns>
        public static StringBuilder GetCompanyTender()
        {
            try
            {
                StringBuilder CompanyMes = new StringBuilder();
                OleDbDataReader DataRead = ClassFile.AccessHelper.ExecuteReader(ClassFile.AccessHelper.ConnectionString, " SELECT T_CompanyTender FROM T_CompanyInfo ", null);
                if (DataRead.HasRows)
                {
                    while (DataRead.Read())
                    {
                        CompanyMes.Append(DataRead["T_CompanyTender"].ToString());
                    }
                }
                DataRead.Close();
                DataRead.Dispose();
                return CompanyMes;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        /// <summary>
        /// 获取公司公告信息 
        /// </summary>
        /// <param name="strClass"></param>
        /// <returns></returns>
        public static StringBuilder GetCompanyNotice()
        {
            try
            {
                StringBuilder CompanyMes = new StringBuilder();
                OleDbDataReader DataRead = ClassFile.AccessHelper.ExecuteReader(ClassFile.AccessHelper.ConnectionString, " SELECT T_CompanyNotice FROM T_CompanyInfo ", null);
                if (DataRead.HasRows)
                {
                    while (DataRead.Read())
                    {
                        CompanyMes.Append(DataRead["T_CompanyNotice"].ToString());
                    }
                }
                DataRead.Close();
                DataRead.Dispose();
                return CompanyMes;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 获取公司其他信息 
        /// </summary>
        /// <param name="strClass"></param>
        /// <returns></returns>
        public static OleDbDataReader GetCompanyInfo()
        {
            try
            {
                return ClassFile.AccessHelper.ExecuteReader(ClassFile.AccessHelper.ConnectionString, " SELECT T_CompanyName,T_CompanyTel,T_CompanyFax,T_CompanyMail,T_CompanyAdress,T_CompanyNo FROM T_CompanyInfo ", null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取提示信息 
        /// </summary>
        /// <param name="strClass"></param>
        /// <returns></returns>
        public static string[] GetSysSPInfo()
        {
            try
            {
                string[] strSql = { " SELECT COUNT(*) FROM T_LeaveInfo WHERE T_LeaveFlag=0 ",
                                        " SELECT COUNT(*) FROM T_BaseOrder WHERE T_OrderFlag=0  ",
                                        " SELECT COUNT(*) FROM T_ProductInfo ",
                                        " SELECT COUNT(*) FROM T_NewsInfo "};
                string[] strRe = new string[4];
                for (int i = 0; i < strSql.Length; i++)
                {
                    strRe[i] = ClassFile.AccessHelper.ExecuteScalar(ClassFile.AccessHelper.ConnectionString, strSql[i], null).ToString();
                }
                return strRe;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
